package com.shop.myException;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyHandlerExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {

//        System.out.println("public class MyHandlerExceptionResolver implements HandlerExceptionResolver {\n");
//        System.out.println(e);

        ModelAndView modelAndView = new ModelAndView();
        String msg2 = "默认错误提示...";

        if (e instanceof MyException) {
            msg2 = ((MyException) e).getMsg();
        }

        String msg = "出bug了，请联系管理员处理";
        modelAndView.addObject("msg", msg);
        modelAndView.addObject("msg2", msg2);
        modelAndView.setViewName("error");
        return modelAndView;
    }
}
